<template lang="pug">
  section.author
    Card(title='接口文档',v-if="$route.meta['/download/apiDocument']")
      Button(slot="extra",icon='md-download',type='primary',@click='handleApiDocDown') 文档下载
      p 文档描述
    Card(title='帮助信息管理文档',v-if="['/download/operatingDocument']")
      Button(slot="extra",icon='md-download',type='primary',@click='handleHelpDocDown') 文档下载
      p 文档描述
    Card(title='接口授权管理',v-if="$route.meta['/apiService/grantAuthorization']")
      Form(:model='formValidate',:label-width='90',style='width:500px')
        FormItem(label='账户名称：')
          Input(placeholder='账户名称',v-model='formValidate.name')
        FormItem(label='账户密码：')
          Input(placeholder='账户密码',type='password',v-model='formValidate.passwd')
        FormItem(label='授权码：',v-if="authCode!==''")
          div(style='height:32px',v-if="showLoading")
            Spin(fix) 加载中...
          span(style='fontSize:14px',v-else) {{authCode}}
        FormItem
          Button(type='primary',@click='handleGetAuthCode') 获取授权码
</template>

<script>
import { asyncAuthor } from '../api'

export default {
  name: 'Author',
  data() {
    return {
      authCode: '',
      showLoading: false,
      formValidate: {
        name: '',
        passwd: ''
      }
    }
  },
  mounted() {},
  methods: {
    handleApiDocDown() {
      window.open(`${process.env.VUE_APP_BASE_API}/download/apiDocument?token=${this.$cookie.get('toke')}`)
      // location.href = `${process.env.VUE_APP_BASE_API}/download/apiDocument?token=${this.$cookie.get('token')}`
    },
    handleHelpDocDown() {
      location.href = `${process.env.VUE_APP_BASE_API}/download/operatingDocument?token=${this.$cookie.get('token')}`
    },
    handleGetAuthCode: async function() {
      try {
        this.authCode = ''
        this.showLoading = true
        this.authCode = (await asyncAuthor.grantAuthorization({ data: { name: this.formValidate.name, pwd: this.formValidate.passwd } })).data.data
        this.showLoading = false
      } catch (error) {
        this.showLoading = false
      }
    }
  }
}
</script>

<style lang="scss">
.author {
  .ivu-card {
    margin-bottom: 20px;
  }
  .ivu-card-extra {
    top: 8px;
  }
  .ivu-spin-fix .ivu-spin-main {
    left: 6%;
  }
}
</style>
